package com.cgt.day3;

import org.junit.Test;

public class OOPDemo {
    @Test
    public void test1(){
        Student student1 = new Student();
        student1.id = 1;
        student1.name = "zx";
        student1.age = 12;
        student1.gender = "男";
        System.out.println(student1.id);
        System.out.println(student1.name);
        System.out.println(student1.age);
        System.out.println(student1.gender);
//        System.out.println(student1.getInfo());
        System.out.println(toString());

        Student student2 = new Student();
        student2.id = 2;
        student2.name = "wangwu";
        student2.age = 24;
        student2.gender = "女";
        System.out.println(student2.id);
        System.out.println(student2.name);
        System.out.println(student2.age);
        System.out.println(student2.gender);
//        System.out.println(student2.getInfo());
        System.out.println(toString());
    }

    @Test
    public void test2() {
        Student student = new Student();
        System.out.println(student.id);
        System.out.println(student.name);
    }

    @Test
    public void test3() {
        int[] array1 = new int[3];
        boolean[] array2 = new boolean[3];
        Student[] array3 = new Student[3];
        for (Student student : array3) {
            System.out.println(student);
        }
    }

    @Test
    public void test4() {
        Student student = null;
        System.out.println(student);//null
        //java.lang.NullPointerException: Cannot read field "id" because "student" is null
        //null.属性   null.方法()
        System.out.println(student.id);
    }

    @Test
    public void test5() {
        //student1: 变量、对象、引用
        Student student1 = new Student();
        student1.id = 1;//对象.属性
        student1.name = "zhangsan";
        student1.age = 623;
        student1.gender = "男";
//        System.out.println(student1.getInfo());
        System.out.println(student1.toString());
        //当打印对象的时候，默认就调用了：对象.toString()
        System.out.println(student1);
    }
}
